#include "../include/ConditionThreadMutex.h"
#include "../include/ThreadManager.h"
#include <iostream>

ThreadMutex mutex;
ConditionThreadMutex cond_1(mutex);    
ConditionThreadMutex cond_2(mutex);    
ConditionThreadMutex cond_3(mutex); 

void *cond_wait (void *arg)
{
    ConditionThreadMutex *cond = reinterpret_cast<ConditionThreadMutex *> (arg);
    cond->wait ();
    std::cout << "cond wakeup [threadid = " << Thread::self () << std::endl;    
    return 0;
}
void notify_cond (int )
{
    cond_3.signal ();
}
int main ()
{
    
    signal (SIGINT, notify_cond);

    mutex.acquire ();
    ThreadManager::instance ()->spawn (cond_wait, &cond_1);
    ThreadManager::instance ()->spawn (cond_wait, &cond_2);
    ThreadManager::instance ()->spawn (cond_wait, &cond_3);

    ThreadManager::instance ()->wait ();
}
